//============================================================================================
/**
 * @file	throw_calc.c
 * @brief	玉投げ計算
 *
 * @author	Nozomu Saito
 *
 * モジュール名:ThClc_
 */
//============================================================================================

#include "throw_calc.h"
#include "common.h"

#define BASE_RAD	(182)		//1°に値するおおよそのラジアン値


//--------------------------------------------------------------------------------------------
/**
 * 表示座標を判定空間座標に変換
 *
 * @param 	inDspX		表示X座標
 * @param	inDspY		表示Y座標
 * @param	outChkX		判定空間X座標
 * @param	outChkZ		判定空間X座標
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
void ThClc_GetChkPosFromDspPos(const int inDspX, const int inDspY, float *outChkX, float *outChkZ)
{

	float in_x,in_y, x,z;
	in_x = inDspX;
	in_y = inDspY;
	z =	(in_y*5.0/52.0)+(293.0/13.0);
	x = ((in_x*(31.0/160.0)+(in_y/8.0))-10*(31.0/20.0)-10.0) / ((145.0/368.0)+(in_y/512.0));

	*outChkZ = z;
	*outChkX = x;

///	OS_Printf("表示座標%d,%d ==> 判定座標%f,%f\n",inDspX, inDspY , x, z);
}

//--------------------------------------------------------------------------------------------
/**
 * 判定空間座標を表示座標に変換
 *
 * @param	inChkX		判定空間X座標
 * @param	inChkZ		判定空間Z座標
 * @param 	outDspX		表示X座標
 * @param	outDspY		表示Y座標
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
void ThClc_GetDspPosFromChkPos(const float inChkX, const float inChkZ, int *outDspX, int *outDspY)
{
	float in_x,in_z, x,y;
	int int_y;
	in_x = inChkX;
	in_z = inChkZ;
	y = (in_z*in_z*in_z)/7600.0 + 11.0 - ((24.0-in_z)*(24.0-in_z)*(24.0-in_z)/4400.0)- 1.0 + 4.0/((in_z-57.0)*(in_z-57.0)+1.0);
	y *= 8.0;
	*outDspY = y;

	x = (8.0/23.0)*in_x + 10.0 - (((y/8.0)-10.0)*(20.0/31.0)*(64.0-in_x)/64.0);
	x *= 8.0;
	*outDspX = x;

///	OS_Printf("int表示座標%d,%d\n",*outDspX, *outDspY);

///	OS_Printf("判定座標%f,%f ==> 表示座標%f,%f\n",inChkX, inChkZ , x, y);
}

//--------------------------------------------------------------------------------------------
/**
 * 方向のぶれをセット
 *
 * @param	inTilt		傾き
 * @param	ioVec		ベクトル
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
void ThClc_FixDir( const u8 inTilt, VecFx32 *ioVec )
{
	MtxFx43 mtx;
	u16 rad;
	int tilt = inTilt;

	tilt = tilt - ( gf_rand()%(tilt*2) );
	rad = tilt * BASE_RAD;
	//回転行列作成
	MTX_RotY43(&mtx, FX_SinIdx(rad), FX_CosIdx(rad));
	//ベクトルと行列を掛け合わせる
	MTX_MultVec43(ioVec, &mtx, ioVec);
}
